#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,q,s[2010],u,now[2010],flg[2010],num,ans[4000010],cnt=-1,k,dfn[2010],tot;
vector<int> edge[2010];
void dfs(int u){
	ans[++cnt]=u;
	if(!flg[u]) flg[u]=1,num++;
	if(num==n&&u==1) return;
	now[u]++;
	if(now[u]>=s[u]) now[u]=0;
	dfs(edge[u][now[u]]);
}
void dfs1(int u){
	dfn[++tot]=u;
	if(tot>=n) return;
	now[u]++;
	if(now[u]>=s[u]) now[u]=0;
	dfs(edge[u][now[u]]);
}
signed main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	scanf("%lld%lld",&n,&q);
	for(int i=1;i<=n;i++){
		scanf("%lld",&s[i]);
		for(int j=1;j<=s[i];j++){
			scanf("%lld",&u);
			edge[i].push_back(u);
		}
	}
	dfs(1),dfs1(1);
	while(q--){
		scanf("%lld",&k);
		if(k<=cnt) printf("%lld\n",ans[k]);
		else printf("%lld\n",dfn[(k-cnt-1)%n+1]);
	}
	return 0;
}
